//
//  SZYHMyBankViewController.m
//  苏州银行
//
//  Created by rimi on 15/8/20.
//  Copyright (c) 2015年 IOS. All rights reserved.
//

#import "SZYHMyBankViewController.h"
#import "Config.h"
#import "SZYHScheduleViewController.h"
#import "SZYHMemoViewController.h"
#import "SZYHCommunicationViewController.h"
#import "SZYHGreetingCardViewController.h"
#import "SZYHSurveyViewController.h"


@interface SZYHMyBankViewController ()

@property (nonatomic, strong)NSArray *titleArray;
@property (nonatomic, strong)NSMutableArray *titleButtonArray;
@property (nonatomic, strong)SZYHScheduleViewController *scheduleVC;
@property (nonatomic, strong)SZYHMemoViewController *memoVC;
@property (nonatomic, strong)SZYHCommunicationViewController *communicationVC;
@property (nonatomic, strong)SZYHGreetingCardViewController *gcVC;
@property (nonatomic, strong)SZYHSurveyViewController *surveyVC;

@end

@implementation SZYHMyBankViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.863 green:0.863 blue:0.875 alpha:1.000];
    
    _titleArray = @[@"日程安排",@"备忘录",@"通讯录",@"历史节日贺卡",@"调查问卷"];
    _titleButtonArray = [NSMutableArray array];
    
    [self initializeUserInterface];
}

- (void)initializeUserInterface{
    
    NSInteger x = 0;
    for (int i = 0; i < 5; i++) {
        NSString *string = _titleArray[i];
        
        UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        titleButton.frame = CGRectMake( 30 + x, 20, string.length * 20 + 20 , 30);
        [titleButton setBackgroundImage:IMGNAME(@"我的银行_未选中_菜单按钮") forState:UIControlStateNormal];
        [titleButton setBackgroundImage:IMGNAME(@"我的银行_选中_菜单按钮") forState:UIControlStateSelected];
        [titleButton setTitle:string forState:UIControlStateNormal];
        [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.view addSubview:titleButton];
        titleButton. adjustsImageWhenHighlighted = NO;
        [titleButton addTarget:self action:@selector(titleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        x += string.length * 20 + 35;
        titleButton.tag = i;
        [_titleButtonArray addObject:titleButton];
    }
}

- (void)titleButtonEvent:(UIButton *)sender{
    for (UIButton *button in _titleButtonArray) {
        button.selected = NO;
        if (button == sender) {
            button.selected = YES;
        }
    }
    if (sender.tag == 0) {
        if (!_scheduleVC) {
            _scheduleVC = [[SZYHScheduleViewController alloc]init];
        }
        _scheduleVC.fame = CGRectMake(10, 70, CONTENT_WIDTH - 20, CONTENT_HEIGHT - 80);
        [self.view addSubview:_scheduleVC.view];
        [self addChildViewController:_scheduleVC];
    }
    if (sender.tag == 1) {
        if (!_memoVC) {
            _memoVC = [[SZYHMemoViewController alloc]init];
        }
        _memoVC.fame = CGRectMake(10, 70, CONTENT_WIDTH - 20, CONTENT_HEIGHT - 80);
        [self.view addSubview:_memoVC.view];
        [self addChildViewController:_memoVC];
    }
    if (sender.tag == 2) {
        if (!_communicationVC) {
            _communicationVC = [[SZYHCommunicationViewController alloc]init];
        }
        _communicationVC.fame = CGRectMake(10, 70, CONTENT_WIDTH - 20, CONTENT_HEIGHT - 80);
        [self.view addSubview:_communicationVC.view];
        [self addChildViewController:_communicationVC];
    }
    if (sender.tag == 3) {
        if (!_gcVC) {
            _gcVC = [[SZYHGreetingCardViewController alloc]init];
        }
        _gcVC.fame = CGRectMake(10, 70, CONTENT_WIDTH - 20, CONTENT_HEIGHT - 80);
        [self.view addSubview:_gcVC.view];
        [self addChildViewController:_gcVC];
    }
    if (sender.tag == 4) {
        if (!_surveyVC) {
            _surveyVC = [[SZYHSurveyViewController alloc]init];
        }
        _surveyVC.fame = CGRectMake(10, 70, CONTENT_WIDTH - 20, CONTENT_HEIGHT - 80);
        [self.view addSubview:_surveyVC.view];
        [self addChildViewController:_surveyVC];
    }
  
}
@end
